#include "Player.h"

Player::Player(void)
	: _spawnPoint(), _nick (), _life(100),
	  _objeto(NULL), _killCount(0), _connected(true)
{

}
Player::Player( const String& nick, Object& obj, const Cor& cor  )
	: _spawnPoint(), _nick (nick), _life(100),
	  _objeto( &obj ), _killCount(0), _connected(true)
{
	if( obj.getMaterial() )
		obj.getMaterial()->cor = cor;
}

Player::Player( const Player& rhs )
	: _spawnPoint(), _nick (), _life(100),
	  _objeto(NULL), _killCount(0), _connected(true)
{
	*this = rhs;
}
Player& Player::operator=( const Player& rhs )
{
	if( this != &rhs )
	{
		_spawnPoint = rhs._spawnPoint;
		_nick = rhs._nick;
		_life = rhs._life;
		_objeto = rhs._objeto;
		_killCount = rhs._killCount;
		_connected = rhs._connected;
	}

	return *this;
}

void Player::respawn(void) {

	_objeto->posicao = _spawnPoint;
	_life = 100.0;

	// TODO "olhar" para o centro

}

void Player::setSpawnPoint(const Vetor2d& sp) {
	_spawnPoint = sp;
}

const Vetor2d& Player::getSpawnPoint(void) const {
	return _spawnPoint;
}

const String& Player::getNick(void) const {
	return _nick;
}

bool Player::damage(double dano) {
	_life -= dano;

	return isDead();
}

double Player::getLife(void) const {
	return _life;
}

bool Player::isDead(void) const {
	return _life <= 0.0;
}

bool Player::isConnected(void) const {
	return _connected;
}

Object& Player::getObjeto(void) {
	return *_objeto;
}
